import request from '../../utils/Request'
import PageUtils from '../../utils/PageUtils'

// 机构列表-树形
export const listCatalogTree = bId => {
  if (bId === undefined || bId === null) {
    bId = 0
  }
  return request({
    method: 'get',
    url: '/api/cms/catalog/list/tree/' + bId,
    params: {}
  })
}

export const saveCatalog = data => {
  return request({
    method: 'post',
    url: '/api/cms/catalog/save',
    data: data
  })
}

export const createCatalog = (data, idempotentCode) => {
  return request({
    method: 'post',
    url: '/api/cms/catalog/create',
    data: data,
    headers: {
      common: {
        idempotent: idempotentCode
      }
    }
  })
}

export const updateCatalog = data => {
  return request({
    method: 'post',
    url: '/api/cms/catalog/update',
    data: data
  })
}

export const updateCatalogStatus = (catalogId, status) => {
  return request({
    method: 'get',
    url: '/api/cms/catalog/' + catalogId + '/status/' + status,
    params: {}
  })
}

export const deleteCatalog = bId => {
  return request({
    method: 'get',
    url: '/api/cms/catalog/delete/' + bId,
    params: {}
  })
}

export const listCatalog = (data, current, size) => {
  let pageUrl = PageUtils.page(current, size)
  return request({
    method: 'get',
    url: '/api/cms/catalog/list?' + pageUrl,
    params: data
  })
}


export const selectCatalog = bId => {
  return request({
    method: 'get',
    url: '/api/cms/catalog/select/' + bId,
    params: {}
  })
}